import { createSlice, PayloadAction } from "@reduxjs/toolkit";

export type PageInfoType = {
  title: string;
  desc?: string;
  js?: string;
  css?: string;
  isPublished?: boolean;
};

const INIT_STATE: PageInfoType = {
  title: "",
  desc: "",
  js: "",
  css: "",
};

export const userSlice = createSlice({
  name: "pageInfo",
  initialState: INIT_STATE,
  reducers: {
    //初始化信息
    resetPageInfo: (
      state: PageInfoType,
      action: PayloadAction<PageInfoType>
    ) => {
      return action.payload;
    },
    //修改标题
    changePageInfoTitle: (
      state: PageInfoType,
      action: PayloadAction<string>
    ) => {
      return {
        ...state,
        title: action.payload,
      };
    },
  },
});
export const { resetPageInfo, changePageInfoTitle } = userSlice.actions;
export default userSlice.reducer;
